package com.xbongbong.saas.service;

import com.xbongbong.paas.pojo.dto.CreditCardBillDTO;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.saas.enums.CreditCardBillTypeEnum;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author xingxing.xiao
 * @date 2020/12/23 14:37
 */
public interface CreditCardBillService {

    /**
     * 添加信用流水(信用释放，当前只有已核销、预收款核销类型回款单能释放信用)
     * 改为批量：有批量生成回款单的入口，因此需要批量释放信用
     * 参数：{"corpid":"xbbxingdemo","userId":"xing001","platform":"web","frontDev":"1","distributorMark":1,"type":1,"refId":100,"refNo":"v234324","businessType":"110","amount":100,"customerId":"307697","customerName":"经销商1010"}
     * @param creditCardBillDTO
     * @return java.lang.Integer
     * @throws XbbException
     * @since v1.0
     * @version v1.0
     */
    void addBatchCreditCardBill(CreditCardBillDTO creditCardBillDTO) throws XbbException;

    /**
     * 根据type和refId回滚新增的信用流水es--直接删除es数据
     * @param corpid 公司id
     * @param creditCardBillTypeEnum 信用流水类型
     * @param refId 信用流水内refId
     * @return com.xbongbong.saas.domain.entity.ext.CreditCardBillEntityExt
     * @throws XbbException
     * @author zcp
     * @since v1.0
     * @version v1.0
     */
    void addRollback(String corpid, CreditCardBillTypeEnum creditCardBillTypeEnum, Long refId) throws XbbException;

    /**
     * 判断这些订货单里有没有用信用支付的订货单
     * @param orderIds 订货单ids
     * @return
     * @throws XbbException
     */
    boolean checkOrderCardBill(List<Long> orderIds, String corpid) throws XbbException;

    /**
     * 计算信用需要还的额度
     * @param distributorId
     * @param paymentIds
     * @param corpid
     * @return
     * @throws XbbException
     */
    BigDecimal calcCreditPayLimit(Long distributorId, List<Long> orderIds, List<Long> paymentIds, String corpid) throws XbbException;

    /**
     * 计算需要释放的剩余额度
     * @param distributorId
     * @param orderId
     * @param corpid
     * @return
     * @author xingxing.xiao
     * @date 2021/02/27 22:07
     */
    BigDecimal calcCreditRemainLimit(Long distributorId, Long orderId, String corpid) throws XbbException;

    /**
     * 名称一致性同步
     * @param corpid
     * @param customerId
     * @param customerName
     * @throws XbbException
     */
    void dataConsistencyUpdateCustomer(String corpid, Long customerId, String customerName) throws XbbException;
}
